﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="fhdb" content="true">
    <title>推广榜</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="css/extension.css">
    <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
</head>
<body>
    <div class="backBox" onClick="javascript:history.back(-1);">
        <span class="glyphicon glyphicon-chevron-left"></span>
    </div>
    <div class="topTitle">
        推广榜
    </div>
    <!-- 顶部导航 -->
    <div class="topNav">
        <div class="navBox checked">
            <div>
                日榜
            </div>
        </div>
        <div class="navBox">
            <div>
                周榜
            </div>
        </div>
        <div class="navBox ">
            <div>
                月榜
            </div>
        </div>
        <div class="navBox ">
            <div>
                我的推广
            </div>
        </div>
        <div class="navBox ">
            <div>
                推广订单
            </div>
        </div>
    </div>
    <!-- 榜单 -->
    <div class="bd_banner">
        <div class="bd_title"><span class="bd_title_font">本日推广排行榜</span><img class="tgbdImg" src="images/huo.png" /></div>
    </div>
    <div class="bd_bdxq">

    </div>
    
    <div class="tgdd">
    </div>
    <div class="MyTg" style="display:none;">
        <div class="userNumber">
            <input type="text" class="form-control tbnumber" placeholder="请输入会员ID">
            <button type="button" class="btn btn-danger">查询</button>
        </div>
        <div class="UserXq">

        </div>
    </div>
</body>
</html>
<script type="text/javascript">
    $(function () {
        bangdan("日榜");
        $('.topNav').on('click', '.navBox', function () {
            const $this = $(this)
            const index = $this.index()
            var text = $this[0].innerText;
            $this.addClass('checked').siblings().removeClass('checked')
            if ($.trim(text) == "日榜") {
                $(".tgdd").hide();
                $(".MyTg").hide();
                $(".tgbdImg").show();
                $(".bd_bdxq").show();
                $(".bd_title_font").text("本日推广排行榜");
                bangdan("日榜");
            }
            if ($.trim(text) == "周榜") {
                $(".tgdd").hide();
                $(".MyTg").hide();
                $(".tgbdImg").show();
                $(".bd_bdxq").show();
                $(".bd_title_font").text("本周推广排行榜");
                bangdan("周榜");
            }
            if ($.trim(text) == "月榜") {
                $(".tgdd").hide();
                $(".MyTg").hide();
                $(".tgbdImg").show();
                $(".bd_bdxq").show();
                $(".bd_title_font").text("本月推广排行榜");
                bangdan("月榜");
            }
            if ($.trim(text) == "我的推广") {
                $(".tgdd").hide();
                $(".tgbdImg").hide();
                $(".bd_bdxq").hide();
                $(".MyTg").show();
                tgQuery();
            }
            if ($.trim(text) == "推广订单") {
                $(".bd_bdxq").hide();
                $(".MyTg").hide();
                $(".tgdd").show();
                tgdingdan();
            }
        })
    })
    function bangdan(state) {
        $.ajax({
            type: "POST",
            data: { state: state },
            url: "../../BaseRefWeb.aspx?stype=ISpOrderFun&method=GetTuiGuangTop&type=sp",
            success: function (result) {
                var data = JSON.parse(result);
                if (data.msg == "_timeout") {
                    window.location.href = "../UserLogin/Login.html";
                }
                else {
                    var html = "";
                    for (var i = 0; i < data.length; i++) {
                        var num = i + 1;
                        html += '<div class="bd_bdxq_top">';
                        if (i == 0) {
                            html += '<div><img src="images/jin.png" style="width:20px; height:20px;" /></div>';
                        } else if (i == 1) {
                            html += '<div><img src="images/yin.png" style="width:20px; height:20px;" /></div>';
                        } else if (i == 2) {
                            html += '<div><img src="images/tong.png" style="width:20px; height:20px;" /></div>';
                        } else {
                            html += '<div style = "width:20px;" > ' + num + '、</div>';
                        }
                        html += '<div>' + data[i].TB_JSPERSON + '</div>';
                        html += '<div>' + data[i].count + '人</div>';
                        html += '</div>';
                    }
                    $(".bd_bdxq").empty();
                    $(".bd_bdxq").append(html);
                }
            }
        });
    }
    function tgQuery() {
        $.ajax({
            type: "POST",
            url: "../../BaseRefWeb.aspx?stype=ISpOrderFun&method=GetTuiGuangCount&type=sp",
            success: function (result) {
                var data = JSON.parse(result);
                $(".bd_title_font").text("当前推广总人数：" + data.DTCOUNT + "人");
            }
        });
        tgListTable("");
    }
    $(".btn-danger").click(function () {
        var number = $(".tbnumber").val();
        tgListTable(number);
    })
    function tgListTable(Number) {
        $.ajax({
            type: "POST",
            data: { state: Number },
            url: "../../BaseRefWeb.aspx?stype=ISpMemberFun&method=GetMyTuiGuang&type=sp",
            success: function (result) {
                var data = JSON.parse(result);
                if (data.length == 0) {
                    $(".UserXq").empty();
                    $(".UserXq").append("当前推广信息为空！");
                    return;
                }
                var html = "";
                html += '<table class="table">';
                html += '<tr>';
                html += '<td>会员ID</td><td>注册时间</td><td>购买数量</td><td>商品总价</td>';
                html += '</tr>';
                for (var i = 0; i < data.length; i++) {
                    html += '<tr>';
                    html += '<td>' + data[i].TB_NUMBER + '</td><td>' + data[i].TB_ADDTIME + '</td><td>' + data[i].BuyCount + '</td><td>' + data[i].PriceCount + '</td>';
                    html += '</tr>';
                }
                html += '</table>';
                $(".UserXq").empty();
                $(".UserXq").append(html);
            }
        });
    }
    function tgdingdan(start,end,select) {
        $.ajax({
            type: "POST",
            data: { start: start, end: end, select: select},
            url: "../../BaseRefWeb.aspx?stype=ISpOrderFun&method=GetFxOrder&type=sp",
            success: function (result) {
                var data = JSON.parse(result);
                var html = "";
                var priceCount = 0;
                html += '<select class="form-control" id="s" ><option value="全部">全部</option><option value="一级">一级</option><option value="二级">二级</option></select>';
                html += '<div style="margin-top:5px;margin-left:5px;"><input type="date" id="datestart" style="width:40%" />至<input type="date" id="dateend" style="width:40%" /><button id="tgddbtn">查询</button></div>';
                for (var i = 0; i < data.length; i++) {
                    html += '<div class="orderId"><span>' + data[i].TB_BUYER + '</span><span>已完成</span></div><div class="line"></div><div class="commodity"><img src="../../' + data[i].TB_GOODS_PATH + '" alt="">';
                    html += '<div class="information"><p>' + data[i].TB_GOODS_NAME + '</p><div class="amount">￥' + data[i].TB_PRICE + '</div></div></div><div class="line"></div>';
                    html += '<div class="pay"><span>订单编号：</span><span>' + data[i].TB_NUMBER + '</span></div >';
                    html += '<div class="buyTime"><span> 下单时间：</span><span>' + data[i].TB_ADDTIME + '</span></div>';
                    html += '<div class="space"></div><div class="commission" ><span>预计佣金：</span><span>+</span><span>' + data[i].TB_YJ_PRICE + '</span></div>';
                    priceCount += Number(data[i].TB_PRICE);
                }
                $(".tgbdImg").hide();
                $(".bd_title_font").text("累计推广人" + data.length + "单" + priceCount.toFixed(2) + "元");
                $(".tgdd").empty();
                $(".tgdd").append(html);
                $("#tgddbtn").click(function () {
                    tgdingdan($("#datestart").val(), $("#dateend").val(), $("#s option:selected").text());
                })
            }
        });
    }
</script>